#254 通过web应用查看日志
from flask import Flask, render_template,request,escape
app=Flask(__name__)
@app.route("/viewLog")
def view_the_log()->str:
    contents =[]
    with open('vsearch.log') as logStream:
        for line in logStream :
            contents.append([])
            for item in line.split('|'):
                contents[-1].append(escape(item))
    #列表转换成string返回
    return str(contents)

@app.route("/viewLogTemplate")
def view_the_log2()->'html':
    contents =[]
    with open('vsearch.log') as logStream:
        for line in logStream :
            contents.append([])
            for item in line.split('|'):
                contents[-1].append(escape(item))
    titles =('form data','remote_addr', 'user_agent', 'result')

    return render_template('viewlog.html',the_title='view log', the_row_titles=titles, the_data=contents,)
if(__name__=='__main__'):
    app.run(debug=True)


##page 259